<template>
  <table class="oa-classify__table" cellpadding="0"  cellspacing="0" v-if="getMy && getMy.length">
    <tr class="oa-classify__hd">
      <td width="40%">事务编号</td>
      <td width="20%">当前步骤</td>
      <td>发起时间</td>
      <td style="width:20%">状态</td>
      <td style="width:130px">操作</td>
    </tr>
    <tr v-for=" ( item, index ) in getMy " :key="index" class="sp-section__list-group">
      <td @click="lookFunc(item)">
        <div>
          {{item.approve_name}}{{item.code}}
        </div>
        <span class="oa-classify__sub">{{item.reason}}</span>
      </td>
      <td>
        <template v-if="item.status !== -200">
          <span v-if="item.is_end == 0">{{item.node_name}}({{item.node_truename}})</span>
          <el-link v-else type="danger">结束（{{item.created_at}}）</el-link>
        </template>
        <template v-else>
          <el-link type="danger">已终止（{{item.created_at}}）</el-link>
        </template>
      </td>
      <td>{{item.created_at}}</td>
      <td>
        <el-tag v-if="item.is_end == 0 && item.status !== -200">进行中</el-tag>
        <el-tag type="danger" v-else-if="item.is_end == 1 && item.status === -200">已终止</el-tag>
        <el-tag v-else :type="type">结束</el-tag>
      </td>
      <td>
        <template v-if="item.status !== -200">
          <el-button type="danger" @click="stopFunc(item)">终止</el-button>
          <el-button type="primary" @click="lookFunc(item)">查看</el-button>
        </template>
      </td>
    </tr>
  </table>
</template>
<script>
import { stopStep } from '@/api/oa'

export default {
  props: ['getMy'],
  data () {
    return {
      type: 'danger'
    }
  },
  methods: {
    lookFunc (item) {
      window.localStorage.setItem('approve', JSON.stringify(item))
      this.$router.push({ name: 'oaMain', query: { approve: item, from: 'my', active: 4 } })
    },
    stopFunc (item) {
      console.log('item', item)
      stopStep({
        openid: window.localStorage.getItem('token'),
        workflow_id: item.workflow_id
      }).then(res => {
        console.log('res', res)
        // if (res.status) {
        // }
        this.$message[res.status ? 'success' : 'error']('终止成功')
      })
      this.$emit('refresh')
    }
  }
}
</script>
